<script language="javascript">

$(function(){		
	
	$("#content").css("height","860px");	
	
	//carrega Disciplinas no combo
	$("#txtDisciplina").load("actions/ajaxlistarDisciplinasComboAction2.php");
	
	
})

	tinyMCE.init({
		mode : "textareas",
		theme : "advanced",
		plugins : "safari,style,layer,table,advlink,emotions,insertdatetime,preview,print,fullscreen,noneditable,wordcount,visualblocks",

		theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,|,insertdate,inserttime,|,forecolor,backcolor,|,print,|,ltr,rtl,|,fullscreen",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : false,
		noneditable_leave_contenteditable : true,
		content_css : "js/tinymce/examples/css/content.css",
		setup : function(ed) { 
			ed.onPaste.add(function(ed, e, o) { 
				tinymce.dom.Event.cancel (e); 
			}); 
		}
	});

	function submitTrabalho(status){
		
		$('#formTrabalhoAluno').ajaxForm({
				dataType: 'json',
				data:{ 
					status:status,
					descricao:tinyMCE.get('txtDescricaoEditor').getContent()
				},
				success: function(responseText, statusText) {
					if(responseText.sucesso){
						$.jAlert(responseText.mensagem, '', function(result) {
							if(status=="F"){
								$("#btnFinalizar").hide();
								$("#btnSalvar").hide();
								tinymce.activeEditor.getBody().setAttribute('contenteditable', false);
							}
							window.location = "/?pg=home";											 
						});
						
					}else{
						$.jAlert(responseText.mensagem, '', function(result) {});
					}
			}
	
		}).submit();
		
	}
	
	//busca Trabalho atraves do liste trabalho
	function getTrabalhoId(Id_Trabalho){
		$.ajax({
			type:"POST",
			url:"actions/ajaxlistarTrabalhoTextAreaAction.php",
			data:{trabalho_id_list:Id_Trabalho},
			dataType:"json",
			success: function(data, textStatus, request){
				if(data['status']=="F"){
					$("#btnFinalizar").hide();
					$("#btnSalvar").hide();
					tinymce.activeEditor.getBody().setAttribute('contenteditable', false);
				}
				if(data['conceito']!="" && data['conceito']!=null){
					$("#notaObtida").html("Nota obtida: "+data['conceito']);
				}
				$("#txtTrabalhoDescrito").html(data['descricao']);
				
				tinyMCE.execCommand('mceInsertContent',false,data['resposta']);
				
			}	
		});					 
	}
		 
	//busca Trabalhos atraves do filtro da Disciplina
	function getDisciplina(disciplina_id){
		 $("#txttrabalho").html("<option value=''>Carregando...</option>");		 
		 setTimeout(function(){
		 //carrega Trabalhos no combo
		$("#txttrabalho").load("actions/ajaxlistarTrabalhosComboAction.php?disciplina_id="+disciplina_id);								 
	}, 2000)}
	
 
</script>

<div id="formularios">

    <fieldset style="height:690px;width:800px;padding:20px;">
    
        <legend>
            <img src="images/topoPaginas/Icon_Trabalhos_Menu.png"/>
        </legend>
        
        
        <div id="btnSairForms">
            <a href="/?pg=home" title="Sair" style="border:0;">
                <img src="images/btnOutros/btnSairForms.png"/>
            </a>
        </div>
        <form id="formTrabalhoAluno" name="formTrabalhoAluno" method="post" action="actions/trabalhosAlunoAction.php">
          <table width="783" border="0" cellspacing="0" cellpadding="0">
             <tr>
               <td height="52">&nbsp;</td>
               <td><span id="title">Diciplina:</span>
                 <select name="txtDisciplina" id="txtDisciplina" onchange="getDisciplina(this.value, 0)" class="required" style="width:180px;">
                   <option>Selecione...</option>
               </select></td>
               <td align="center"><span id="notaObtida" style="color:#F00;font-size:12px;"></span></td>
             </tr>
             <tr>
               <td width="3" height="52"><label></label></td>
             <td width="324"><span id="title">Trabalho:</span>
               <select name="txttrabalho" id="txttrabalho" onchange="getTrabalhoId(this.value, 0)" class="required" style="width:180px;">
                 <option>Selecione...</option>
               </select></td>
               <td width="456">&nbsp;</td>
             </tr>
             <tr>
               <td>&nbsp;</td>
               <td colspan="2"><br />Trabalho descrito: </td>
             </tr>
             <tr>
               <td>&nbsp;</td>
               <td colspan="2">
               		<div id="txtTrabalhoDescrito" style="font-size:11px;color: #8B8682;background: #FFF; border:1px solid #C1CDC1;width:780px;height:100px;margin-bottom:30px;"></div>
			   </td>
             </tr>
             <tr>
               <td>&nbsp;</td>
               <td colspan="2">Solução do trabalho: </td>
             </tr>
             <tr>
               <td colspan="3">
			   <textarea name="txtDescricaoEditor" id="txtDescricaoEditor" cols="60" rows="5" style="width:785px;height:300px;"></textarea>				
					</td>
              </tr>
             <tr>
               <td colspan="3"> </td>
              </tr>
       </table>
</form>

 		 <div style="position:relative;width:800px;height:40px;text-align:center;">
         	<br />
            <a href="javascript:void(0);" title="Salvar Alterações" id="btnSalvar"  onclick="submitTrabalho('A');" style="border:0;text-decoration:none;padding-left:12px;">
                <img src="images/btnOutros/btnSalvar.png" />
        	</a>
            &nbsp;&nbsp;
			<a href="javascript:void(0);" title="Finalizar Trabalho" id="btnFinalizar" onclick="submitTrabalho('F');" style="border:0;text-decoration:none;padding-left:12px;">
                <img src="images/btnOutros/btnFinalizar.png" />
        	</a>
        </div>

</fieldset>
</div>